import 'package:kq_flutter_core_widget/utils/ex/num_ex.dart';

import 'base/axis.dart';

/// 配置X轴相关数据
///
/// Created by wanggaowan on 2023/9/15 09:48
class XAxis extends BaseXAxis {
  XAxis(
      {super.lineColor,
      super.lineWidth,
      super.lineDash,
      super.startPadding,
      super.endPadding,
      super.labelCount,
      super.labelTextSize,
      super.labelColor,
      super.labelOffsetAxis,
      super.axisValueFormatter,
      super.labelAlign,
      super.labelOverAlign,
      super.labelMaxLines,
      super.textOverflow,
      super.gridLineColor,
      super.gridLineWidth,
      super.gridUseEndPadding,
      super.gridUseStartPadding,
      super.gridLineDash,
      super.labelHeight,
      super.labelMinHeight = 0,
      super.labelMaxHeight,
      super.labelHorizontalPadding,
      super.labelRotation});
}

/// 横向图表的X轴
///
/// Created by wanggaowan on 2023/12/1 11:34
class HorizontalXAxis extends BaseXAxis {
  HorizontalXAxis(
      {super.lineColor,
      super.lineWidth,
      super.lineDash,
      super.startPadding,
      super.endPadding,
      // 轴上标签数量。比如设置标签数量为6，如果使用默认的ValueFormatter,设置Y轴最小、最大值分别为0、100，则Y轴标签值为0，20，40，60，80，100
      super.labelCount,
      super.labelTextSize,
      super.labelColor,
      super.labelOffsetAxis,
      AxisValueFormatter? axisValueFormatter,
      super.labelAlign,
      super.labelOverAlign,
      super.labelMaxLines,
      super.textOverflow,
      super.gridLineColor,
      super.gridLineWidth,
      super.gridUseEndPadding,
      super.gridUseStartPadding,
      super.gridLineDash,
      super.labelHeight,
      super.labelMinHeight = 0,
      super.labelMaxHeight,
      super.labelHorizontalPadding,
      this.min = 0,
      this.step = 20})
      : super(
          axisValueFormatter: axisValueFormatter ??
              (int position) {
                if (labelCount <= 0) {
                  return Label();
                }

                return Label(value: (min + (position * step)).format('#0.##'));
              },
        );

  /// 绘制坐标起始值
  final double min;

  /// 每个网格步长
  final double step;

  /// 绘制坐标最大值
  double get max {
    if (labelCount <= 0) {
      return 0;
    }

    return min + (labelCount - 1) * step;
  }
}
